import { UserProfilesAPI } from "@/request/api";
export default {
  namespaced: true,
  state: {
    cartTotal: 0,
    userInfo: {
      nickName: "Daniao",
      coin: "9999",
      headImg: require("../../assets/img/userImg.f8bbec5e.png"),
    },
  },
  getters: {},

  mutations: {
    //更新用户信息
    changeUserInfo(state, payload) {
      state.cartTotal = payload.cartTotal;
      state.userInfo = payload.userInfo;
    },
    //用户信息初始化
    initUserInfo(state, payload) {
      state.cartTotal = "0";
      state.userInfo = {
        nickName: "Daniao",
        coin: "9999",
        headImg: require("../../assets/img/userImg.f8bbec5e.png"),
      };
    },
  },
  actions: {
    //异步获取用户信息
    async asyncChangeUserInfo({ commit }) {
      let res = await UserProfilesAPI();
  
      commit("changeUserInfo", {
        cartTotal: res.data.cartTotal,
        userInfo: res.data.userInfo,
      });
    },
  },
};
